//
//  addGroupController.m
//  soccer
//
//  Created by 上官千城 on 15/9/4.
//  Copyright (c) 2015年 上官千城. All rights reserved.
//

#import "addGroupController.h"

@interface addGroupController ()

@end

@implementation addGroupController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"创建群组";
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;

    [self.view addSubview:self.tableView];
    
    
    
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellInfo = @"addGroupCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellInfo];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellInfo];
        
    }
    if (indexPath.section == 0) {
        UIButton *add = [UIButton buttonWithType:UIButtonTypeCustom];
        add.frame = CGRectMake(20, 10, 60, 60);
        [add addTarget:self action:@selector(addButtonFriend) forControlEvents:UIControlEventTouchUpInside];
        [add setImage:[UIImage imageNamed:@"添加图片@2x"] forState:UIControlStateNormal];
//        add.backgroundColor = [UIColor orangeColor];
        [cell addSubview:add];
        //点击Cell无色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.section == 1 && indexPath.row == 0) {
        cell.textLabel.text = @"置顶";
        UISwitch *top = [[UISwitch alloc]initWithFrame:CGRectMake(WIDTH-70, 10, 0, 0)];
        [top setOn:YES animated:YES];
        [top addTarget:self action:@selector(topAction:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:top];
        //点击Cell无色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.section == 1 && indexPath.row == 1) {
        cell.textLabel.text = @"静音";
        UISwitch *mute = [[UISwitch alloc]initWithFrame:CGRectMake(WIDTH-70, 10, 0, 0)];
        [mute setOn:YES animated:YES];
        [mute addTarget:self action:@selector(muteAction:) forControlEvents:UIControlEventValueChanged];
        [cell addSubview:mute];
        //点击Cell无色
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.section == 1 && indexPath.row == 2) {
        cell.textLabel.text = @"举报";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    
    return cell;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return 80;
    }
    return 50;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section ==0) {
        return 1;
    }
    
    return 3;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1 && indexPath.row == 2) {
        NSLog(@"举报");
    }

}
//置顶方法
-(void)topAction:(UISwitch *)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        NSLog(@"on");
    }else {
        NSLog(@"off");
    }
}
//静音方法
-(void)muteAction:(UISwitch *)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        NSLog(@"on");
    }else {
        NSLog(@"off");
    }
}

//把好友添加进讨论组
-(void)addButtonFriend
{
    addMemverController *view = [[addMemverController alloc]init];
    [self.navigationController pushViewController:view  animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
